package suanfa;

import java.util.Arrays;
import java.util.HashMap;

public class test2 {
    public static int[] twoSum(int[] nums, int target) {//map key不能重复
        HashMap<Integer,Integer> map=new HashMap<>();
        for (int i = 0; i < nums.length; i++) {
            map.put(nums[i],i);
        }
        for (int i = 0; i < nums.length; i++) {
            int pi=target-nums[i];
            if (map.containsKey(pi)&&map.get(pi)!=i){
                return  new int[] {i,map.get(pi)};
            }
        }
        return  null;
    }
    public static  void main(String[] args){
        int[] nums={2,7,11,15};
        System.out.println(Arrays.toString(twoSum(nums,9)));
    }
}
